<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	BoardDao boardDao = new BoardDaoImpl();//取到板块Dao的实例
	TopicDao topicDao = new TopicDaoImpl();//取得主题Dao的实例
	UserDao userDao = new UserDaoImpl();//得到用户Dao的实例
	Map mapBoard = boardDao.findBoard();//取得Map形式的版块信息
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>论坛首页</title>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<style type="text/css">
		*{
			padding: 0;
			margin: 0;
		}
		#apDiv1 {
			position: absolute;
			left: 1px;
			top: 1px;
			width: 99.5%;
			height: 50px;
			z-index: 1;
		}
		#apDiv2 {
			position: absolute;
			left: 1px;
			top: 51px;
			width: 99.5%;
			height: 30px;
			z-index: 2;
			background-color: #e0f0f9;
		}
		#apDiv3 {
			position: absolute;
			left: 1px;
			top: 85px;
			width: 99.5%;
			height: 500px;
			z-index: 3;
		}
		.style1{
			font-family: "黑体";
			font-weight: bold;
			font-size: 40px;
			color: #3399cc;
		}
		.style2{
			color: black;
			font-size: 20px;
		}
		.style3{
			background-color: #FFA500;
		}
		tr:hover{
				background-color: #FFFF66;
		}
	</style>
  </head>
  <body>
	<div id="apDiv1">
		<div align="center" class="style1">校园BBS系统</div>
	</div>
	<c:choose>
	<c:when test="${seesionScope.user == null }">
	<%-- <%
		if(session.getAttribute("user")==null){
	%> --%>
	<div class="style2" id="apDiv2">
		&nbsp;您尚未&nbsp;&nbsp;<a href="login.jsp" target="_blank">登录</a>&nbsp;&nbsp;|
		&nbsp;&nbsp;<a href="reg.jsp" target="_blank">注册</a>
	</div>
	</c:when>
<%-- 	<%
		}else{
			User loginUser = (User)session.getAttribute("user");
	%> --%>
	<c:otherwise>
	<div class="style2" id="apDiv2">
		&nbsp;您好：&nbsp;&nbsp;${sessionScope.user.userName }
		<%-- <jsp:getProperty name="user" property="userName" scope="session"> --%>
		<%-- <%=loginUser.getUserName() %> --%>
		&nbsp;&nbsp;|
		&nbsp;&nbsp;<a href="manage/doLogout.jsp" target="_blank">注销</a>
	</div>
	</c:otherwise>
	</c:choose>
	<%-- <%
		}
	%> --%>
	
	<div id="apDiv3">
		<table width="100%" height="503" border="1" cellpadding="0" cellspacing="0">
			<tr>
				<td colspan="2" class="style2" style="text-align: center">论坛</td>
				<td width="10%" class="style2" style="text-align: center">主题</td>
				<td width="70%" class="style2" style="text-align: center">最后发表</td>
			</tr>
			<!-- 主版块 -->
			<%
				List listMainBoard = (List)mapBoard.get(new Integer(0));
				for(int i=0;i<listMainBoard.size();i++){
					Board mainBoard = ((Board)listMainBoard.get(i));//循环取得主版块
			 %>
			<tr class="style3">
				<td colspan="4" class="style2" style="text-align: center">
					<%=mainBoard.getBoardName() %>
				</td>
			</tr>
			<!-- 子版块 -->
			<%
				List listSonBoard = (List)mapBoard.get(new Integer(mainBoard.getBoardId()));
				for(int j=0;j<listSonBoard.size();j++){
					Board sonBoard = (Board)listSonBoard.get(j);//循环取得子版块
					Topic topic = new Topic();//最后发表的主题
					User user = new User();//最后发表的主题的作者
					int boardId = sonBoard.getBoardId();
					List listTopic = topicDao.findListTopic(1,boardId);//取得该板块主题列表
					if((listTopic!=null)&&(listTopic.size()>0)){
						topic = (Topic)listTopic.get(0);//取得该板块最后发表的帖子
						user = userDao.findUser(topic.getUserId());
					}
			 %>
			<tr>
				<td width="6%">&nbsp;</td>
				<td width="30%">
					<img src="image/board.gif" width="20" height="29" />
					<span class="style2"><a href="list.jsp?page=1&boardId=<%=boardId %>"><%=sonBoard.getBoardName() %></a></span>
				</td>
				<td style="text-align: center"><%=topicDao.findCountTopic(boardId) %></td>
				<td style="text-align: center">
					<a href="detail.jsp"><%=topic.getTitle() %></a>
					<br>
					<%=user.getUserName() %>&nbsp;&nbsp;&nbsp;
					<span style="color:#00C758;">[<%=topic.getPublishTime() %>]</span>
				</td>
			</tr>
			<%
				}
			}
			%>
		</table>
	</div>
  </body>
</html>
